const { timeFormat } = require('../utils')
/** 微信 统计 */

const wechatCount = (mongoose) => {
  const { Schema, model } = mongoose
  // 微信 订单
  const orderSchema = new Schema(
    {
      userPhoneNo: {
        type: String,
        required: true,
      },
      nickName: {
        type: String,
      },

      productNo: {
        type: Number,
        required: true,
      },
      productName: {
        type: String,
      },
      name: {
        type: String,
      },
      address: {
        type: String,
      },
      message: {
        type: String,
      },
      price: {
        type: String,
      },
    },
    {
      timestamps: true,
    }
  )
  orderSchema.pre('save', function (next) {
    formatDate(this.createdAt)
    formatDate(this.updatedAt)
    next()
  })
  const orderCount = model('wechat_order_manage', orderSchema)
  return {
    orderCount,
  }
}

// 自定义日期格式化函数
function formatDate(date) {
  if (!date) return null
  return timeFormat(date)
}

module.exports = wechatCount
